#ifndef __MAV_DB_H__
#define __MAV_DB_H__

#define MAV_MOUNT_DIR "/mnt/sd1"
//#define MAV_MOUNT_DIR "sd1" /* for test */

/*** memory database to index ***/
#define MAV_DB_INITIAL_RECNUM  30 // 30 days
#define MAV_DB_INITIAL_ITEMNUM 48 // 24h
struct mav_db_item
{
    unsigned int seq;
    char fname[16];
    time_t starts;
    time_t endts;
    int next; /* next item seq,-1 end */
};
struct mav_db_record
{
    unsigned int seq;
    char date[16];
    unsigned int item_num;
    unsigned int item_maxcnt;
    int item_head; /* frist item seq */
    int next; /* next record seq,-1 end */
    struct mav_db_item *item;
};
struct mav_db_list
{
    unsigned int num;
    unsigned int maxcnt;
    int head; /* frist record seq */
    pthread_mutex_t lock;
    struct mav_db_record *reclist;
};

#include "protocal_pkg.h"

#define MAV_TIMELINE_MAX REPLAY_SECTION_MAX 
typedef struct replay_date st_mav_date;
typedef struct replay_dateline st_mav_db_dateline;
//typedef struct replay_timeline st_mav_db_timeline;

typedef struct mav_db_timeline
{
    int num;
    struct 
    {
	time_t tstart;
	time_t tend;
    }section[MAV_TIMELINE_MAX];
}st_mav_db_timeline;
/*
typedef struct mav_date
{
    unsigned short year;
    unsigned char month;
    unsigned char day;
}st_mav_date;
typedef struct mav_db_dateline
{
    int num;
    struct mav_date section[MAV_TIMELINE_MAX];
}st_mav_db_dateline;
*/

int mav_db_init_list(void);
int mav_db_add_item(const char *recname);
int mav_db_del_item(const char *recname);
FILE *mav_db_get_file(time_t tstart,int direction,time_t *ptend);
void mav_db_exit_list(void);
void mav_db_print_list(void);
int mav_db_build_timeline(st_mav_db_timeline *timeline);
int mav_db_build_dateline(st_mav_db_dateline *dateline);
int mav_db_build_daytline(st_mav_date date,st_mav_db_timeline *daytline);

#endif

